<template>
  <span v-html="time"></span>
</template>
<script>
  export default {
    data() {
      return {
        time: '',
        flag: false
      }
    },
    mounted() {
      this.timeDown()
      let time = setInterval(() => {
        this.timeDown()
      }, 60000)
    },
    props: {
      endTime: {
        type: String
      }
    },
    methods: {
      timeDown() {
        if (this.endTime) {
          //中文格式转换 世界标准格式
          const endTime = new Date(this.endTime.replace(/-/g, "/")).getTime()
          const nowTime = new Date().getTime();
          let time = Math.ceil((endTime - nowTime) / 1000 / 60)
          let absoluteValue = Math.abs(time)
          if (absoluteValue >= '60') {
            let h = Math.floor(absoluteValue / 60)
            let m = absoluteValue % 60 == 0 ? '' : `${absoluteValue % 60}分`
            if (time > '0') {
              this.time = `距离超时只有${h}小时${m}`
            } else {
              this.time = `<span style="color:#e13f00;">已超时${h}小时${m}</span>`
            }
          } else {
            if (time > '0') {
              this.time = `距离超时只有${time}分钟`
            } else {
              this.time = `<span style="color:#e13f00;">已超时${absoluteValue}分</span>`
            }
          }
        } else {
          this.time = `未知时间`
        }
      },
    }
  }
</script>
